<?php
!defined('P_W') && exit('Forbidden');

require_once(R_P . 'lib/upload.class.php');

class HouseLogoUpload extends uploadBehavior {
	
	var $db;
	var $hid;
	var $attachs;

	function HouseLogoUpload($hid) {
		global $db;
		parent::uploadBehavior();
		$this->hid = (int)$hid;
		$this->db =& $db;
		
		$db_imgsize = 2000;
		$this->ftype = array(
			'gif'  => $db_imgsize,				'jpg'  => $db_imgsize,
			'jpeg' => $db_imgsize,				'bmp'  => $db_imgsize,
			'png'  => $db_imgsize
		);
	}

	function allowType($key) {
		list($t) = explode('_', $key);
		return $t == 'logo';
	}

	function getFilePath($currUpload) {
		$filename = $this->hid . '.' . $currUpload['ext'];
		$savedir = 'house/logo/';
		return array($filename, $savedir, '', '');
	}

	function update($uploaddb) {
		$this->attachs = $uploaddb;
	}

	function getLogo() {
		$ret = current($this->attachs);
		return isset($ret['fileuploadurl']) ? $ret['fileuploadurl'] : '';
	}
}

class HouseBannerUpload extends uploadBehavior {
	
	var $db;
	var $hid;
	var $attachs;

	function HouseBannerUpload($hid) {
		global $db;
		parent::uploadBehavior();
		$this->hid = (int)$hid;
		$this->db =& $db;
		
		$db_imgsize = 2000;
		$this->ftype = array(
			'gif'  => $db_imgsize,				'jpg'  => $db_imgsize,
			'jpeg' => $db_imgsize,				'bmp'  => $db_imgsize,
			'png'  => $db_imgsize
		);
	}

	function allowType($key) {
		list($t) = explode('_', $key);
		return $t == 'banner';
	}

	function getFilePath($currUpload) {
		$filename = 'banner_' . $this->hid . '.' . $currUpload['ext'];
		$savedir = 'house/logo/';
		return array($filename, $savedir, '', '');
	}

	function update($uploaddb) {
		$this->attachs = $uploaddb;
	}

	function getBanner() {
		$ret = current($this->attachs);
		return isset($ret['fileuploadurl']) ? $ret['fileuploadurl'] : '';
	}
}
?>